package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Record;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class RecordDao {
	
	private DBHelp<Record> db = new DBHelp<Record>();
	
	public void Save (String id,String content,String createtime,String t_employee_id,String t_contact_id) {
		String sql = "insert into t_record(id,content,createtime,t_employee_id,t_contact_id) values(?,?,?,?,?)";
		db.executeSQL(sql, id,content,createtime,t_employee_id,t_contact_id);
	}
	
	public List<Record> FindAll () {
		String sql = "select id,content,createtime,t_employee_id,t_contact_id from t_record";
		return db.executeQueryForList(sql, new RecordRowMapper());
	}

	private class RecordRowMapper implements RowMapper<Record> {
		
		public Record mapperRow (ResultSet rs) throws SQLException {
			
			Record record = new Record();
			record.setId(rs.getString("id"));
			record.setContent(rs.getString("content"));
			record.setCreatetime(rs.getString("createtime"));
			record.setT_employee_id(rs.getString("t_employee_id"));
			record.setT_contact_id(rs.getString("t_contact_id"));
			return record;
		}
	}
}
